// 定义类型接口
import { Post, Get, Patch, Delete } from '@/utils/request.ts'

export interface PaginationParams {
  pageNo?: number
  pageSize?: number
}

export interface CreatePermissionDto {
  name: string
  code: string
  type: string
  description?: string
}

export interface UpdatePermissionDto {
  name?: string
  code?: string
  type: string
  description?: string
}

export interface Permission {
  id: number
  name: string
  code: string
  description?: string
  createdAt: Date
  updatedAt: Date
}

export interface PaginationResult<T> {
  records: T[]
  total: number
}

export const createPermissionApi = (data: CreatePermissionDto) => {
  return Post<CreatePermissionDto, PaginationResult<Permission>>('/blog/permissions', data)
}

export const getPermissionListApi = (data: PaginationParams) => {
  return Get<PaginationParams, PaginationResult<Permission>>('/blog/permissions', data)
}

export const updatePermissionApi = (id: string | number, data: UpdatePermissionDto) => {
  return Patch<UpdatePermissionDto, never>('/blog/permissions/' + id, data)
}

export const deletePermissionApi = (id: string | number) => {
  return Delete<never, never>('/blog/permissions/' + id)
}
